package leetcode.editor.cn.q7xx

class Q781MediumNumRabbits {
    fun numRabbits(answers: IntArray): Int {
        val hashMap = hashMapOf<Int, Int>()
        for (i in answers) {
            hashMap[i] = hashMap.getOrDefault(i, 0) + 1
        }
        var ans = 0
        hashMap.forEach { (y, x) ->
            ans += (x + y) / (y + 1) * (y + 1)
        }
        return ans
    }
}